package com.happy.mvcframe.utils;

import android.app.Activity;

import com.happy.mvcframe.R;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.animators.AnimationType;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.PictureFileUtils;

import java.util.List;

/**
 * @describe 图片选择工具类
 * @date 2020/5/13
 * @author wjw
 */
public class PictureSelectorUtil {

    /**
     * @describe 打开相机
     */
    public static void openGallery(Activity activity){
        PictureSelector.create(activity)
                .openCamera(PictureMimeType.ofImage())
                .isWeChatStyle(true)
                .cutOutQuality(100)
                .imageEngine(GlideEngine.createGlideEngine())
                .forResult(PictureConfig.REQUEST_CAMERA);
    }
    /**
     * @describe 打开相机
     */
    public static void openGallery(Activity activity, int width, int height){
        PictureSelector.create(activity)
                .openCamera(PictureMimeType.ofImage())
                .isWeChatStyle(true)
                .imageEngine(GlideEngine.createGlideEngine())
                .isEnableCrop(true)//开启裁剪
                .cutOutQuality(100)
                .freeStyleCropEnabled(false)//裁剪框是否可拖拽
                .isDragFrame(true)//是否可拖动裁剪框(固定)
                .scaleEnabled(true)
                .withAspectRatio(width,height)
                .cropImageWideHigh(width,height)
                .forResult(PictureConfig.REQUEST_CAMERA);
    }
    /**
     * @describe 选择相册 单图 裁剪
     */
    public static void selectPictureOnlyNeedCrop(Activity activity, int width, int height){
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .theme(R.style.picture_WeChat_style)
                .isWeChatStyle(true)
                .imageEngine(GlideEngine.createGlideEngine())
                .selectionMode(PictureConfig.SINGLE)//设置单选
                .isPageStrategy(true)//开启分页模式
                .isCamera(false)//列表不显示拍照片功能
                .maxSelectNum(1)
                .minSelectNum(1)
                .imageSpanCount(3)
                .isGif(false)//不显示Gif
                .isEnableCrop(true)//开启裁剪
                .freeStyleCropEnabled(false)//裁剪框是否可拖拽
                .isDragFrame(true)//是否可拖动裁剪框(固定)
                .scaleEnabled(true)
                .isOriginalImageControl(true)//开启原图选项
                .withAspectRatio(width,height)
                .cropImageWideHigh(width,height)
                .setRecyclerAnimationMode(AnimationType.ALPHA_IN_ANIMATION)//列表动画效果
                .forResult(PictureConfig.CHOOSE_REQUEST);

    }
    /**
     * @describe 选择相册 单图 不裁剪
     */
    public static void selectPictureOnly(Activity activity){
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .theme(R.style.picture_WeChat_style)
                .imageEngine(GlideEngine.createGlideEngine())
                .selectionMode(PictureConfig.SINGLE)//设置单选
                .isPageStrategy(true)//开启分页模式
                .isCamera(false)//列表不显示拍照片功能
                .maxSelectNum(1)
                .minSelectNum(1)
                .imageSpanCount(3)
                .isGif(false)//不显示Gif
                .isEnableCrop(false)//开启裁剪
                .isOriginalImageControl(true)//开启原图选项
                .setRecyclerAnimationMode(AnimationType.ALPHA_IN_ANIMATION)//列表动画效果
                .forResult(PictureConfig.CHOOSE_REQUEST);

    }

    /**
     * @describe 选择相册 单图 裁剪
     */
    public static void selectPictureAllMoreNeedCrop(Activity activity, int width, int height){
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .theme(R.style.picture_WeChat_style)
                .isWeChatStyle(true)
                .imageEngine(GlideEngine.createGlideEngine())
                .selectionMode(PictureConfig.SINGLE)//设置单选
                .isPageStrategy(true)//开启分页模式
                .isCamera(false)//列表不显示拍照片功能
                .maxSelectNum(9)
                .minSelectNum(1)
                .imageSpanCount(3)
                .isGif(false)//不显示Gif
                .isEnableCrop(true)//开启裁剪
                .freeStyleCropEnabled(false)//裁剪框是否可拖拽
                .isDragFrame(true)//是否可拖动裁剪框(固定)
                .scaleEnabled(true)
                .isOriginalImageControl(true)//开启原图选项
                .withAspectRatio(width,height)
                .cropImageWideHigh(width,height)
                .setRecyclerAnimationMode(AnimationType.ALPHA_IN_ANIMATION)//列表动画效果
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    /**
     * @describe 选择相册 多图 不裁剪
     */
    public static void selectPictureAllMore(Activity activity){
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .theme(R.style.picture_WeChat_style)
                .imageEngine(GlideEngine.createGlideEngine())
                .isPageStrategy(true)//开启分页模式
                .isCamera(false)//列表不显示拍照片功能
                .maxSelectNum(9)
                .minSelectNum(1)
                .imageSpanCount(3)
                .isGif(false)//不显示Gif
                .isOriginalImageControl(true)//开启原图选项
                .setRecyclerAnimationMode(AnimationType.ALPHA_IN_ANIMATION)//列表动画效果
                .forResult(PictureConfig.CHOOSE_REQUEST);

    }

    /**
     * @describe 清除缓存
     */
    public static void deleteCacheDirFile(Activity activity){
        PictureFileUtils.deleteAllCacheDirFile(activity);
    }

    /**
     * @describe 预览图片
     */
    public static void openExternalPreview(Activity activity, int position, List<LocalMedia> selectList){
        PictureSelector.create(activity)
                .themeStyle(R.style.picture_WeChat_style)
                .imageEngine(GlideEngine.createGlideEngine())
                .isNotPreviewDownload(true)
                .openExternalPreview(position,selectList);
    }
    /**
     * 预览视频
     */
    private static void externalPictureVideo(Activity activity, String video_path){
        PictureSelector.create(activity).externalPictureVideo(video_path);
    }

}
